﻿using DataStructureSample.ListDs;
using System;
using System.Collections.Generic;
using System.Text;

namespace DataStructureSample.QueueDs
{
    public class LinkedQueue<T>
        : IQueueDs<T>
    {
        private Node<T> _header;
        private Node<T> _footer;
        private int _count = 0;
        public LinkedQueue()
        {

        }
        public int Count => _count;

        public void Clear()
        {
            _header=null;
            _footer = null;
            _count = 0;
        }

        public T Dequeue()
        {
            if (_count==0)
            {
                return default(T);
            }
            else
            {
                var temp = _header.Data;
                _count--;
                return temp;
            }
        }

        public void Enqueue(T item)
        {
            var temp = new Node<T>(item);
            if (_count==0)
            {
                _header = temp;
            }
            else if (_count==1)
            {
                _footer = temp;
            }
            else
            {
                _footer.Next = temp;
            }
            _count++;
        }

        public int GetLength()
        {
            return _count;
        }

        public bool IsEmpty()
        {
            return _count==0;
        }

        public T Peek()
        {
            if (_count == 0)
            {
                return default(T);
            }
            else
            {
                var temp = _header.Data;
                return temp;
            }
        }
    }
}
